using System;
using System.Collections.Generic;
using System.Text;

namespace Ltf.Diffs.Diff3Docs.NoBase
{
	public class MergeViewLeft: DiffDocument
	{
		public MergeViewLeft(string fileName)
			: base(fileName) { }

		public override void LoadResults(Diff3Results results)
		{
			// showing base and server changes - added lines to keep in sync with local
			// main file based on server file.
			int blankLineOffset = 0;
			foreach (Diff3Results.Diff3Hunk hunk in results.Hunks)
			{
				if (!hunk.IsLocalDiff)
				{
					bool insertOffSetAdj = hunk.ServerRange.IsAdd ? false : true;
					LineState insertLineState = hunk.ServerRange.IsAdd ? LineState.Deleted : LineState.ChangedFrom;
					LineState markLineState = hunk.BaseRange.IsAdd ? LineState.Inserted : LineState.ChangedTo;

					int paddLines = Math.Max(hunk.LocalRange.LineCount, hunk.ServerRange.LineCount + hunk.BaseRange.LineCount);

					// if it's a three way change (IsAllDiff) then make it as a potential conflict
					if (hunk.IsAllDiff)
					{
						if (markLineState == LineState.ChangedTo)
							markLineState = LineState.ConflictChange;

						if (markLineState == LineState.Inserted)
							markLineState = LineState.ConflictAdd;

						if (insertLineState == LineState.Deleted)
							insertLineState = LineState.ConflictDelete;
					}

					if (!hunk.BaseRange.IsAdd)
						paddLines -= InsertChanges(hunk.ServerRange.From, insertLineState, hunk.BaseLines, ref blankLineOffset, insertOffSetAdj);
					
					if (!hunk.ServerRange.IsAdd)
						paddLines -= MarkChanges(hunk.ServerRange.From, markLineState, hunk.ServerRange.Interval, blankLineOffset, true);

					if (!hunk.IsDeletion)
						InsertMarkedPadding(hunk.ServerRange.To, LineState.SyncOnly, paddLines, ref blankLineOffset, false);

				}
			}

		}
	}
}
